package cn.itsource.controller.blog;

import cn.itsource.blog.domain.articletype.ArticleType;
import cn.itsource.blog.query.articletype.ArticleTypeQuery;
import cn.itsource.service.blog.IArticleTypeService;
import cn.itsource.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articleType")
public class ArticleTypeController {
    @Autowired
    private IArticleTypeService articleTypeService;

    @GetMapping
    public List<ArticleType> select(){
        return articleTypeService.selectAll();
    }

    @PatchMapping
    public JsonResult deleteMore(@RequestBody Long[] ids){
        try {
            articleTypeService.deleteMore(ids);
            return JsonResult.success("删除用户数据成功！");
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error();
        }
    }
    //获取分页
    @PostMapping
    public PageInfo<ArticleType> queryPage(@RequestBody ArticleTypeQuery articleTypeQuery){

        return articleTypeService.queryArticleType(articleTypeQuery);
    }

    @DeleteMapping("/{id}")
    public JsonResult delete(@PathVariable("id") Integer id){
        articleTypeService.delete(id);
        return JsonResult.success("删除用户数据成功！");
    }

    @PutMapping
    public JsonResult update(@RequestBody ArticleType articleType) {
        System.out.println(articleType);
        articleTypeService.update(articleType);
        return JsonResult.success("修改用户数据成功！");
    }

    @GetMapping("/typeTree")
    public List<ArticleType> treeType() {
        return articleTypeService.treeType();
    }

   /* @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {
        List<ArticleType> list = articleTypeService.selectAll();
        ExcelUtil.exportExcel(list, "智慧校园管理系统-老师信息", "老师信息表", ArticleType.class, "Teachers", response);
    }*/
}
